<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投诉标题" prop="title"><el-input v-model="queryParams.title" placeholder="请输入投诉标题" clearable @keyup.enter.native="handleQuery" /></el-form-item>
      <el-form-item label="手机号" prop="phone"><el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" /></el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"><el-button type="primary" icon="el-icon-edit" :disabled="single" @click="handleUpdate" v-hasPermi="['management:feedback:edit']">查看</el-button></el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['management:feedback:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="feedbackList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="投诉标题" align="center" prop="title" />
      <el-table-column label="投诉时间" align="center" prop="createTime" width="250" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
        <template slot-scope="scope">
          <el-button  type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['management:feedback:edit']">查看</el-button>
          <el-button  type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['management:feedback:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 查看内容对话框 -->
    <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="title">
          <div class="abc">{{ form.title }}</div>
        </el-form-item>
        <el-form-item label="内容">
          <div class="abc">{{ form.content }}</div>
        </el-form-item>
        <el-form-item label="照片" v-if="form.pic">
          <el-image class="lpic" :fit="'contain'" :src="baseUrl + item" :preview-src-list="[baseUrl + item]" v-for="(item, index) in form.pic" :key="index"></el-image>
        </el-form-item>
        <el-form-item label="手机号" prop="phone" v-if="form.phone">
          <div class="abc">{{ form.phone }}</div>
        </el-form-item>
        <el-form-item label="时间" prop="createTime">
          <div class="abc">{{ form.createTime }}</div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listFeedback, getFeedback, delFeedback, addFeedback, updateFeedback, exportFeedback } from '@/api/management/feedback';

export default {
  name: 'Feedback',
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建议反馈表格数据
      feedbackList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        phone: null,
        orderByColumn: 'createTime', //排序字段
        isAsc: 'desc' //排序方式
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询建议反馈列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        phone: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查看内容 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getFeedback(id).then(response => {
        this.form = response.data;
        if (this.form.pic) {
          this.form.pic = this.form.pic.split(',');
        }
        this.open = true;
        this.title = '查看内容';
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除建议反馈编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delFeedback(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess('删除成功');
        })
        .catch(() => {});
    }
  }
};
</script>
